package com.dlu.safe_construction.common;

import lombok.Data;

import java.io.Serializable;

/**
 * Created by 李家兴
 * Date 2020/1/31
 * Description
 */
@Data
public class ApiResult<T> implements Serializable {
    private int code;
    private T data;
    private String message;
    private String success;

    public ApiResult() {
        this.code = 1;
    }

    public ApiResult(T data) {
        this.code = 1;
        this.data = data;
    }

    public ApiResult(int code, T data, String message, String success) {
        this.code = code;
        this.data = data;
        this.message = message;
        this.success = success;
    }

    public static <T> ApiResult<T> success() {
        return new ApiResult<>(0, null, null, "success");
    }

    public static <T> ApiResult<T> success(T data) {
        return new ApiResult<>(0, data, null, "success");
    }

    public static <T> ApiResult<T> fail(int code, String message) {
        return new ApiResult<>(code, null, message, "false");
    }

    public static <T> ApiResult<T> fail(int code) {
        return new ApiResult<>(code, null, null, "false");
    }
}
